<?php
namespace App\Services\Sms;
use App\Services\Sms\Sms\SmsLogic;
/**
 * @Author: ws
 * @Date:   2018-06-12 16:23:45
 * @Last Modified by:   Marte
 */
class Sms 
{
    /*添加一个短信配置模板（模板+apikey等）*/
    public function addSms($data): array 
    {
        if (empty($data)) {
            return null_data($data,"参数不能为空！");
        }
        $data = init_array($data,['app_id'=>0,'other_app_read'=>'','is_public'=>0,'action'=>' ','description'=>'','sms_info'=>[]]);
        ValidateSms::checkValidate($data, ['app_id','is_public','action','sms_info']);
        return (new SmsLogic())->addSms($data);
    }

    /*编辑某个短信配置*/
    public function editSms($data): array 
    {

        /*if (empty($data)) {
            return null_data($data,"参数不能为空！");
        }*/
        $data = init_array($data,['id'=>0,'app_id'=>0,'other_app_read'=>'','is_public'=>0,'action'=>' ','description'=>'','sms_info'=>[]]);
        $validateInitData = ['id' => $data['id'],'temp' => 'editSms'];
        ValidateSms::checkValidate($data, ['action','is_public','sms_info'], true, $validateInitData);
        return (new SmsLogic())->editSms($data);
    }

   /* protected function _updateSms($data, bool $isEdit): array 
    {
        $scene = $isEdit ? 'edit' : '';
        //接收数据的验证
        $validate = validate($this->smsValidate);
        if(!$validate->scene($scene)->check($data)){ return verify_err(null, $validate->getError()); }
        if(isset($data['sms_info']) && !$validate->scene('smsInfo')->check($data['sms_info'])){ 
            return verify_err(null, $validate->getError()); 
        }
        //对所属应用下的记录做基本验证
        $checkApp = $this->_baseCheckApp($data, '', 'edit', $this->smsValidate, $this->smsLogic, 'dbOneInfo');
        if($checkApp['status'] != SUCCESS_STATUS){
            return $checkApp;
        }

        if($isEdit){
            return $this->logic($this->smsLogic)->editSms($data);
        }else{
            return $this->logic($this->smsLogic)->addSms($data);
        }
    }*/

    /*获取某应用下的所有短信模板配置*/
    public function smsList($data): array 
    {
        $data = init_array($data,['app_id'=>0,'page'=>1,'listRows'=>15]);
        $validateInitData = ['app_id' => true,'temp'=>'smsList'];
        ValidateSms::checkValidate($data, ['app_id','page','listRows'], true, $validateInitData);
        return (new SmsLogic())->smsList($data);
    }

    /*获取某个短信配置详情*/
    public function smsInfo($data): array 
    {
         if(!isset($data['id']) && !isset($data['action'])){
            return verify_err(null, 'id和action两者必须传一个');
        }
        $data = init_array($data,['app_id'=>0,'id'=>0,'action'=>'']);
        $validateInitData = ['app_id' => true,'temp'=>'smsInfo'];
        ValidateSms::checkValidate($data, ['id','action'], true, $validateInitData);
        return (new SmsLogic())->smsInfo($data);
    }

    /*删除某短信配置*/
    public function delOneSms($data): array 
    {
        $data = init_array($data,['app_id'=>0,'id'=>0]);
        ValidateSms::checkValidate($data, ['id']);
        return (new SmsLogic())->delOneSms($data);
    }

    /*发送单条短信*/
   /* public function sendOne($data): array 
    {
        $data = $this->receiveData(['send_info'=>[]]);

        $validate = validate($this->smsValidate);
        if(!$validate->scene('sendInfo')->check($data['send_info'])){ 
            return verify_err(null, $validate->getError()); 
        }

        $data['smsName'] = config('smsName');
        if($data['smsName']){
            return $this->logic($this->smsLogic)->sendOne($data);
        }else{
            return auto_failure(null, '未配置发送短信的方式');
        }
    }*/

    /*群发短信*/
   /* public function batchSend($data): array 
    {
        $data = $this->receiveData(['send_info'=>[]]);

        $validate = validate($this->smsValidate);
        if(!$validate->scene('sendInfos')->check($data['send_info'])){ 
            return verify_err(null, $validate->getError()); 
        }

        $data['smsName'] = config('smsName');
        if($data['smsName']){
            return $this->logic($this->smsLogic)->batchSend($data);
        }else{
            return auto_failure(null, '未配置发送短信的方式');
        }
    }*/


}